app.controller('roleEditController', ['$scope', 'httpWrapService', 'dialogs', '$state', '$stateParams',
                        '$location', '$anchorScroll', 'AlertFactory','validationService',
                function ($scope, httpWrapService, dialogs, $state, $stateParams, $location, $anchorScroll, AlertFactory,validationService) {
    $scope.entity = {};

    $scope.id = $stateParams.id;
    $scope.type = $stateParams.type || 'add';
    $scope.Alert = AlertFactory.newInstance();

    if($scope.id) {
    	httpWrapService.post('system/role/view/' + $scope.id + '.do').then(function (res) {
    		$scope.entity = res.data.entity;
    		$scope.type = 'update';
    	});
    }

    $scope.unique = function(value){
        return validationService.unique({
            entityName : "common.rbac.po.Role",
            field : "role",
            value : value,
            id : $scope.id
        })
    }

    $scope.save = function () {
        httpWrapService.defaultSave( 'system/role/' + $scope.type + '.do',{
            entity : $scope.entity
        }, $scope).then(function (res) {
            $state.go('app.system.role.list');
        });

        // 保存成功返回列表页面

    }

    $scope.canle = function () {
        // 后退到列表页面
        $state.go('app.system.role.list');
    }


}]);
